package dao.impl;

import dao.ShopCarDao;
import model.ShopCar;
import utils.DaoUtil;
import utils.GenicaDaoImpl;

import java.sql.ResultSet;
import java.util.List;

public class ShopCarDaoImpl extends GenicaDaoImpl<ShopCar,Integer> implements ShopCarDao {

    @Override
    public List<ShopCar> findInfoByUserID(Integer userId) {
        String sql = "select * from shop_car where user_id= ?";
        List<ShopCar> list = (List<ShopCar>) DaoUtil.queryList(ShopCar.class,sql,userId);
        return list;
    }

    @Override
    public boolean addInfo(ShopCar shopCar) {
        String sql = "insert into shop_car (user_id,goods_id,count,price,goods_name) values(?,?,?,?,?)";
        Object[] params = new Object[]{
              shopCar.getUserId(),
              shopCar.getGoodsId(),
              shopCar.getCount(),
              shopCar.getPrice(),
              shopCar.getGoodsName()
        };
        boolean flag = DaoUtil.update(sql,params);
        return flag;
    }

    @Override
    public ShopCar findByUG(Integer userId, Integer goodsId) {
        String sql = "select * from shop_car where user_id=? and goods_id=?";
        Object[] params = new Object[]{
                userId,
                goodsId
        };
        ShopCar shopCar = DaoUtil.query(ShopCar.class,sql,params);

        return shopCar;
    }
}
